﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using DAL;

namespace Arbetsfornedringen.Pages
{
    public partial class Register : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            LabelAccountExist.Text = "";
        }

        protected void ButtonRegister_Click1(object sender, EventArgs e)
        {
            Account account = new Account() { Authority = AuthorityLevel.User, Email = TextBoxUsername.Text, Password = TextBoxPassword.Text };

            bool accountFound = DAL.AccountDB.AuthenticateRegisterValues(account);

            if (accountFound)
                LabelAccountExist.Text = "Email finns redan registrerad. Försök igen.";
            else
            {
                DAL.AccountDB.AddAccount(account);
                Response.Redirect("~\\Pages\\Login.aspx");
            }
        }
    }
}